package com.chenwc.util.threadpool;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author chenwc
 * @date 2023/12/25 14:00
 */
public class NameTreadFactory implements ThreadFactory {

    private final AtomicInteger mThreadNum = new AtomicInteger(1);

    private static final Logger logger = LoggerFactory.getLogger(NameTreadFactory.class);

    @Override
    public Thread newThread(Runnable r) {
        Thread t = new Thread(r, "my-thread-" + mThreadNum.getAndIncrement());
        logger.info(t.getName() + " has been created");
        return t;
    }
}
